﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WEALTH
{
    public partial class SendOrder : ClientBasePage
    {
        private ExcuteDao dao = new ExcuteDao();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session[SessionKeys.CURRENT_MEMBER] == null)
            {
                Response.Redirect("MemberLogin.aspx", true);
                return;
            }
            if (!string.IsNullOrEmpty(Request.QueryString["listviewid"]))
            {
                this.HidTitleId.Value = SpecialCharHandler.HtmlDiscode(Request.QueryString["listviewid"]);
                this.lblTitle.Text = SpecialCharHandler.HtmlDiscode(Request.QueryString["txTitle"]);
                this.lblPoint.Text = SpecialCharHandler.HtmlDiscode(Request.QueryString["point"]);
                lblUserId.Text = ((MemberCurrent)Session[SessionKeys.CURRENT_MEMBER]).M_Name;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                //验证页面数据
                if (!CheckData())
                {
                    return;
                }

                if (dao.Insert_BuyList(
                    ((MemberCurrent)Session[SessionKeys.CURRENT_MEMBER]).M_Name
 != null ? ((MemberCurrent)Session[SessionKeys.CURRENT_MEMBER]).M_Name : "",
                    SpecialCharHandler.HtmlEncode(HidTitleId.Value),
                    SpecialCharHandler.HtmlEncode(lblPoint.Text),
                    SpecialCharHandler.HtmlEncode(txtListCount.Text),
                    "1",
                    SpecialCharHandler.HtmlEncode(txtMemo.Text),
                    SpecialCharHandler.HtmlEncode(txtTel.Text),
                    SpecialCharHandler.HtmlEncode(txtPhone.Text),
                    SpecialCharHandler.HtmlEncode(txtAdd.Text),
                    SpecialCharHandler.HtmlEncode(txtCusName.Text)
                    ) == -1)
                {
                    ReturnList("Customer.aspx?menuid=-1&menutype=会员俱乐部", "兑换成功！");

                }
                else
                {
                    ShowMsg("兑换失败，请确认！", 1);
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message.ToString(), 1);
            }
        }

        /// <summary>
        /// 验证页面内容
        /// </summary>
        /// <returns></returns>
        private bool CheckData()
        {
            if (string.IsNullOrEmpty(txtListCount.Text.TrimEnd()))
            {
                ShowMsg("请输入兑换数量！", 1);
                txtListCount.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(txtCusName.Text.TrimEnd()))
            {
                ShowMsg("请输入收货人姓名！", 1);
                txtCusName.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(txtTel.Text.TrimEnd()))
            {
                ShowMsg("请输入手机号码！", 1);
                txtTel.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(txtAdd.Text.TrimEnd()))
            {
                ShowMsg("请输入收货地址！", 1);
                txtAdd.Focus();
                return false;
            }

            return true;
        }
    }
}